package com.hwhp.dao.console.impl;

import java.util.ArrayList;
import java.util.List;

import com.hwhp.common.Pager;
import com.hwhp.dao.BaseDao;
import com.hwhp.dao.console.PositionDao;
import com.hwhp.entity.SPosition;

public class PositionDaonImpl implements PositionDao{
	
	private BaseDao baseDao = null ;
	
	public boolean deletePosition(SPosition sp){
		boolean success = false ;
		try{
			success = baseDao.delete(sp);
		}catch(Exception e){
			success = false ;
			e.printStackTrace();
		}
	
		return success;
	}

	public boolean editPosition(SPosition sp) {
		boolean success = false ;
		try{
			 baseDao.update(sp);
			 success = true ;
		}catch(Exception e){
			success = false ;
			e.printStackTrace();
		}
		return success;
	}

	
	public SPosition getSposition(String spId) {
		SPosition sp = new SPosition();
		try{
			sp = (SPosition)baseDao.get(SPosition.class,spId);
			
		}catch(Exception e){
			e.printStackTrace();
			
		}
		
		return sp;
	}

	
	public boolean insertPosition(SPosition sp) {
		boolean success = false ;
		try{
			baseDao.save(sp);
			success = true ;
		}catch(Exception e ){
			success = false ;
			e.printStackTrace();
		}
		// TODO Auto-generated method stub
		return success;
	}

	public Pager queryByPager(String hql, int pageSize, int pageNum) {
		Pager page = new Pager();
		try{
			page = baseDao.queryByPage(hql, pageNum, pageSize);
		}catch(Exception e ){
			page = null ;
			e.printStackTrace();
		}
		
		return page;
	}

	
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}

	public List getAllPosts() {
		List postList = new ArrayList();
		String hql = "from SPosition as sp ";
		postList = baseDao.query(hql);
		return postList;
	}

	public boolean deletePosition(Class claz, String spId) {
		boolean success = false ;
		try{
			baseDao.delete(claz, spId);
			success = true ;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}


}
